<?php declare(strict_types=1);
/**
 * This file is part of Swoft.
 *
 * @link     https://swoft.org
 * @document https://swoft.org/docs
 * @contact  group@swoft.org
 * @license  https://github.com/swoft-cloud/swoft/blob/master/LICENSE
 */

namespace App\Task\Listener;

use function context;
use Swoft\Event\Annotation\Mapping\Listener;
use Swoft\Event\EventHandlerInterface;
use Swoft\Event\EventInterface;
use Swoft\Log\Helper\CLog;
use Swoft\Task\TaskEvent;

/**
 * Class FinishListener
 *
 * @since 2.0
 *
 * @Listener(event=TaskEvent::FINISH)
 */
class FinishListener implements EventHandlerInterface
{
    /**
     * @param EventInterface $event
     */
    public function handle(EventInterface $event): void
    {
        /*
            getTaskData 任务处理的结果内容
            getTaskId 任务 ID，对应 Swoole 任务 ID
            getTaskUniqid 全局任务唯一ID，框架生成，与任务投递时的全局任务ID一样
            getServer 获取任务 Server 相关信息
         */
        $fId = context()->getTaskUniqid();
        $taskData = context()->getTaskData();
        CLog::info(json_encode($event->getParams()));
        CLog::info($fId);
        CLog::info($taskData);
    }
}
